import java.util.*;
public class lk20552 {
    public static void main(String[] args) {
        String s="**|**|***|";
        int queries[][]= {{2,5},{5,9}};
        System.out.println(Arrays.toString(platesBetweenCandles1(s, queries)));
    }
    public static int[] platesBetweenCandles1(String s, int[][] queries) {
        int n=s.length();
        int dp[]=new int[n];
        int b[]=new int[queries.length];
        int c[]=new int[n];
        int y=0,e=-1;
        char a[]=s.toCharArray();
        if(a[0]=='*'){
            dp[0]=1;
        }else {
            dp[0]=0;
            e=0;
        }
        for(int i=1;i<n;i++){
            if(a[i]=='*'){
                dp[i]=dp[i-1]+1;
                c[i]=e;
            }
            else {
                e=i;
                dp[i]=dp[i-1];
            }
        }
        int n2=queries.length;
        for(int i=0;i<n2;i++){
            int left=queries[i][0];
            int right = queries[i][1];
            while(a[left]!='|'){
                left++;
            }
            while(a[right]!='|'){
                right--;
            }
            if(right<=left){
                b[y]=0;
                y++;
            }else {
                b[y]=dp[right]-dp[left];
                y++;
            }
        }
        return b;
    }
}
